/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.uct.service.plugins  
 */
package com.apache.uct.service.plugins;

import java.util.List;

import com.apache.api.manager.BaseManager;
import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultMsg;
import com.apache.cache.util.Validator;
import com.apache.uct.common.entity.ActGive;

/**
 * description:  统一插件父类
 * @author dyhou 创建时间：2016-8-18  
 */
public abstract class AbstractSuperPlugin implements PluginConnector {

	protected abstract BaseManager getBaseManager();

	/**
	 * 功能说明：通用保存
	 */
	protected ResultMsg save(ParamsVo vo, String id) {
		ResultMsg rmsg = new ResultMsg("T", "操作成功！");
		boolean mark = false;
		if (Validator.isNotNull(id)) {
			mark = getBaseManager().editInfo(vo);
			if (!mark) {
				rmsg = new ResultMsg("T", "操作失败！");
			}
		} else {
			id = getBaseManager().saveInfo(vo);
			if (Validator.isNull(id)) {
				rmsg = new ResultMsg("T", "操作失败！");
			}
		}
		return rmsg;
	}

	/**
	 * 功能说明：通用删除功能
	 * @param id   删除的id
	 */
	protected ResultMsg delete(String id) {
		ResultMsg rmsg = new ResultMsg("T", "删除成功！");
		ParamsVo vo = new ParamsVo();
		if (Validator.isNotNull(id)) {
			vo.setInfoId(id);
			boolean mark = getBaseManager().deleteInfo(vo);
			if (!mark) {
				rmsg.setFlag("F");
				rmsg.setMsg("删除失败！");
			}
		} else {
			rmsg.setFlag("H");
			rmsg.setMsg("请不要恶意操作！");
		}
		return rmsg;
	}

	/**
	 * 判断是否包含该权限值
	 * @param giveList 分配的权限值
	 * @param actId 权限值id
	 * @return boolean
	 */
	protected boolean hasGive(List<ActGive> giveList, String actId) {
		if (Validator.isEmpty(giveList))
			return false;
		for (int j = 0; j < giveList.size(); j++) {
			ActGive give = giveList.get(j);
			if (actId.equals(give.getActId())) {
				return true;
			}
		}
		return false;
	}
}
